//
//  TeachSignerCalendarController.m
//  Coach_HaiGeEr
//
//  Created by liuchen on 2018/10/17.
//  Copyright © 2018年 海格尔. All rights reserved.
//

#import "TeachSignerCalendarController.h"
#import "BXHCalendarView.h"
#import "NSDate+BXHCalendar.h"
#import "NSDate+BXHCategory.h"

@interface TeachSignerCalendarController ()<BXHCalendarViewDataSource,BXHCalendarViewDelegate>
@property (nonatomic,copy) NSDate *selectDate;
@property (nonatomic,copy) UILabel *timeLabel;
@property (nonatomic,strong) BXHCalendarView *calendarView;
@end

@implementation TeachSignerCalendarController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[CoachTabBarController shareLZHTabbarController].tabBar setHidden:YES];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createSubView];
}


#pragma mark ==========创建视图==========
- (void)createSubView{
    self.title = @"日历";
    self.selectDate = [NSDate date];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setNavBack];
    [self setNavBarButton:@"确定" action:@selector(sure) WithJudge:YES];
    [self.view addSubview:self.timeLabel];
    [self.view addSubview:self.calendarView];
    [self.calendarView goToToday];
}

#pragma mark ==========懒加载==========
- (BXHCalendarView *)calendarView{
    if (!_calendarView) {
        BXHCalendarView *extractedExpr = [BXHCalendarView alloc];
        _calendarView = [extractedExpr initWithFrame:CGRectMake(0, CGRectGetMaxY(self.timeLabel.frame), self.view.bounds.size.width, 190*SCALEUNIT)];
        _calendarView.dataSource = self;
        _calendarView.delegate = self;
    }
    return _calendarView;
}
- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, SYSTEM_TOP, self.view.bounds.size.width, 120*SCALEUNIT)];
        _timeLabel.textColor = [UIColor colorWithHexString:@"#282828"];
        _timeLabel.font = [UIFont systemFontOfSize:LoginFont];
        _timeLabel.textAlignment = NSTextAlignmentLeft;
        _timeLabel.backgroundColor = [UIColor whiteColor];
        _timeLabel.text = [NSString stringWithFormat:@"       %@ %@",[self.selectDate bxh_stringWithFormate:@"yyyy-MM-dd"],[BCMHelper weekdayStringFromDate:self.selectDate]];
    }
    return _timeLabel;
}

#pragma mark ==========BXHCalendarViewDataSource+BXHCalendarViewDelegate==========
- (void)calendarView:(BXHCalendarView *)calendarView willShowMonthView:(BXHCalendarMonthView *)monthView{
    //self.title = [NSString stringWithFormat:@"%@",[monthView.beaginDate bxh_stringWithFormate:@"yyyy-MM-dd"]];
}

- (void)calendarView:(BXHCalendarView *)calendarView dayViewHaveEvent:(BXHCalendarDayView *)dayView{
    dayView.haveEvent = dayView.date.day % 3 == 0;
}

- (void)calendarView:(BXHCalendarView *)calendarView didSelectDayView:(BXHCalendarDayView *)dayView{
    self.selectDate = dayView.date;
    self.timeLabel.text = [NSString stringWithFormat:@"       %@ %@",[self.selectDate bxh_stringWithFormate:@"yyyy-MM-dd"],[BCMHelper weekdayStringFromDate:self.selectDate]];
}

#pragma mark ==========确定功能==========
- (void)sure{
    self.block(self.selectDate);
    [self.navigationController popViewControllerAnimated:YES];
    self.calendarView.hidden = YES;
}
- (void)dealloc{
    [self.calendarView removeFromSuperview];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
